define([
	"js/dropload.min"
], function() {
	return function(content, loading) {
		var token = localStorage.getItem("token");
		loading.hide();
		content.off();
		content.on("click",".weui-form-preview__hd:first-child", function() {
			$(this).nextAll().slideToggle();
		}).on("click","._delete",function(){
			var item = $(this).parent().parent();
			weui.confirm('确定要删除这条记录吗', function() {
				loading = weui.loading("删除中");
				$.post(
					"outgoing/delete.do", {
						"token": token,
						"id":item.data("data").outgoingId
					},
					function(data) {
						loading.hide();
						if(data.ok) {
							item.remove();
							weui.toast('退出成功', {
								duration: 1000
							});
						} else {
							weui.topTips(data.message);
						}
					}, "json"
				);

			}, function() {

			}, {
				title: '删除确认'
			});
			
		});

		var template = content.children(":eq(0)").remove();
		// 页数
		var page = 1;
		// dropload
		content.dropload({
			scrollArea: window,
			loadDownFn: function(me) {
				var p = {
					total:1,
					size:10,
					current:page++,
					token:token
				};
				$.ajax({
					type: 'post',
					url: "outgoing/page.do",
					dataType: 'json',
					data:p,
					success: function(data) {
						if(data.ok){
								
							if(data.page.records==null||data.page.records.length==0){
//								// 锁定
								me.lock();
								// 无数据
								me.noData();
							}else{
								$.each(data.page.records, function(index,row) {
									var item = template.clone().appendTo(content);
									$.each(row, function(name,value) {
										item.find("._"+name).text(value);
									});
									item.data("data",row);
								});
								content.children(".dropload-down").appendTo(content);
							}
						}else{
							weui.topTips(data.message);
						}
						me.resetload();
					},
					error: function(xhr, type) {
						weui.topTips("获取数据异常");
						// 即使加载出错，也得重置
						me.resetload();
					}
				});
			}
		});
		
		
	}
});